package lab03.test14;

import java.sql.*;

public class Test14 {
    public static void main(String[] args) {

        //3+1
        Connection connection = null;
        Statement statement = null;
        ResultSet resultSet = null;

        String insert = "insert INTO"
                + "userinfo(usercode,username,password,email)"
                + "values('7106','曲小声','654321','xiaosheng@163.net')";
        String select = "select*from userinfo";

        try {
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/java_2017?serverTimezone=UTC",
                    "root",
                    "123456");
            statement = connection.createStatement();
            resultSet = statement.executeQuery(select);
            System.out.println("原来的数据是：");
            while (resultSet.next()) {
                System.out.println(resultSet.getString("usercode") + "   ");
                System.out.println(resultSet.getString("username") + "   ");
                System.out.println(resultSet.getString("password") + "   ");
                System.out.println(resultSet.getString("email") + "   ");
            }
            statement.execute(insert);
            resultSet = statement.executeQuery(select);
            System.out.println("现在数据是：");
            while (resultSet.next()) {
                System.out.println(resultSet.getString("usercode") + "   ");
                System.out.println(resultSet.getString("username") + "   ");
                System.out.println(resultSet.getString("password") + "   ");
                System.out.println(resultSet.getString("email") + "   ");
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
